package com.lechuang.goods.controller;

import com.lechuang.common.request.PageRequest;
import com.lechuang.common.result.PageResult;
import com.lechuang.common.result.Result;
import com.lechuang.goods.dto.FreightTemplateListDTO;
import com.lechuang.goods.dto.FreightSaveTemplateDTO;
import com.lechuang.goods.manager.FreightTemplateManager;
import com.lechuang.goods.vo.FreightTemplateDetailVO;
import com.lechuang.goods.vo.FreightTemplateListVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "运费模板" )
@RequestMapping("freight")
public class FreightTemplateController {

    @Resource
    private FreightTemplateManager freightTemplateManager;

    @PostMapping("/pageList")
    @Operation(summary = "运费模板-列表")
    public Result<PageResult<FreightTemplateListVO>> pageList(@RequestBody PageRequest<FreightTemplateListDTO> pageRequest){
        PageResult<FreightTemplateListVO> pageResult = freightTemplateManager.pageList(pageRequest);
        return Result.success(pageResult);
    }

    @PostMapping("/saveOrUpdate")
    @Operation(summary = "运费模板-新增、修改")
    public Result<Object> saveOrUpdate(@RequestBody FreightSaveTemplateDTO freightSaveTemplateDTO){
        freightTemplateManager.saveOrUpdate(freightSaveTemplateDTO);
        return Result.success();
    }

    @PostMapping("/delete")
    @Operation(summary = "运费模板-删除")
    public Result<Object> delete(@Schema(description = "运费模板主键id") @RequestParam Long id){
        freightTemplateManager.delete(id);
        return Result.success();
    }

    @PostMapping("/detail")
    @Operation(summary = "运费模板-详情")
    public Result<FreightTemplateDetailVO> detail(@Schema(description = "运费模板主键id") @RequestParam Long id){
        FreightTemplateDetailVO detailVO = freightTemplateManager.detail(id);
        return Result.success(detailVO);
    }

}
